// 1.导入消息类型,msg/string.hpp
#include "std_msgs/msg/u_int32.hpp"
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

#include <iostream>

#include <sensor_msgs/msg/point_cloud2.hpp>
#include <sensor_msgs/msg/image.hpp>
#include <geometry_msgs/msg/pose.hpp>

#include <cv_bridge/cv_bridge.h>

#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include "opencv2/imgproc.hpp"
#include "opencv2/calib3d.hpp"
#include <opencv2/highgui.hpp>

using std::placeholders::_1;
using std::placeholders::_2;

/*
    创建一个类的节点
*/
class SingleDogNode : public rclcpp::Node
{

public:
    // 构造函数,有一个参数为节点名称
    SingleDogNode(std::string name) : Node(name)
    {
        // 打印自我介绍
        RCLCPP_INFO(this->get_logger(), "大家好,我是四年级学生%s.", name.c_str());
        // 3.创建订阅者
        // 创建一个订阅者来订阅小说
        // sub_novel_ = this->create_subscription<std_msgs::msg::String>("book_dazai", 10, std::bind(&SingleDogNode::topicCallback, this, _1));
        // // 创建一个发布者来给予稿费
        // pub_money_ = this->create_publisher<std_msgs::msg::UInt32>("beautiful_girl_money", 10);

        image_subscription_ = this->create_subscription<sensor_msgs::msg::Image>("image_raw", 10, std::bind(&MinimalSubscriber::topic_callback_image, this, _1));
    }

private:
    // // 3.声明一个订阅者,用于订阅小说
    // rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub_novel_;

    // // 声明一个发布者,用于给予稿费
    // rclcpp::Publisher<std_msgs::msg::UInt32>::SharedPtr pub_money_;

    // // 2.创建回调函数
    // // 收到话题数据的回调函数
    // void topicCallback(const std_msgs::msg::String::SharedPtr msg)
    // {
    //     // 生成钱
    //     std_msgs::msg::UInt32 money;
    //     money.data_ = 10;
    //     // 给钱
    //     pub_money_->publish(money);

    //     RCLCPP_INFO(this->get_logger(), "我已经收到'%s',这是给李的%d元的稿费", msg->data.c_str(), money.data_);
    // };
    void topic_callback_image(const sensor_msgs::msg::Image::SharedPtr msg) const
    {
        cv_bridge::CvImagePtr image_ptr;
        image_ptr = cv_bridge::toCvCopy(msg, "bgr8");
        cv::Mat img_ = image_ptr->image;

        RCLCPP_INFO(this->get_logger(), "I get: '%d'*'%d' image", img_.cols, img_.rows);
    }
    rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
    rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_subscription_;
    rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloud_subscription_;
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    /*产生一个wang2的节点*/
    auto node = std::make_shared<SingleDogNode>("Wang");
    /* 运行节点,检测退出信号*/
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
